VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOCliente"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'---------------------------------------------------------------------------------------
' Module    : DAOCliente
' DateTime  : 30/11/2011 12:10
' Author    :
' Purpose   : Clase DAO Cliente
'---------------------------------------------------------------------------------------
Option Explicit
Private mvarConnection As utilConexion
Public Property Set Connection(ByVal vData As utilConexion)
    Set mvarConnection = vData
End Property
Public Function eliminar(bean As bCliente) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_cliente_eliminar('" + bean.sRuc + "')"
mvarConnection.Connection.Execute sql
eliminar = UtilConstantes.OPT_DATOS_ELIMINADOS

hnderr:
If Err.Number = 0 Then Exit Function
eliminar = UtilConstantes.OPT_ERROR_ENCONTRADO
Err.Clear
End Function
Public Function guardarNuevo(bean As bCliente) As Integer
On Error GoTo hnderr
Dim rst As Recordset
Dim sql As String
Dim result As String
sql = "SELECT * FROM proc_cliente_inserta(cast('" + bean.sRuc + "' as character(11)),'" + bean.sRazonSocial + "','" + bean.sDireccion + "'," + CStr(bean.bEstado.ncodigo) + ")"
Set rst = mvarConnection.Connection.Execute(sql)
result = rst.Fields(0).value
If Mid(result, 1, 1) = UtilConstantes.BIT_INVALIDO Then
    guardarNuevo = UtilConstantes.OPT_RUC_DUPLICADO
    Exit Function
End If
If Mid(result, 2, 1) = UtilConstantes.BIT_INVALIDO Then
    guardarNuevo = UtilConstantes.OPT_RAZSOC_DUPLICADA
    Exit Function
End If
guardarNuevo = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function actualizar(bean As bCliente) As Integer
On Error GoTo hnderr
Dim sql As String
Dim rst As Recordset
Dim result As String

sql = "SELECT * FROM proc_cliente_actualiza(cast('" + bean.sRuc + "' as character(11)),'" + bean.sRazonSocial + "','" + bean.sDireccion + "'," + CStr(bean.bEstado.ncodigo) + ")"
Set rst = mvarConnection.Connection.Execute(sql)
result = rst.Fields(0).value
If Mid(result, 1, 1) = UtilConstantes.BIT_INVALIDO Then
    actualizar = UtilConstantes.OPT_RAZSOC_DUPLICADA
    Exit Function
End If

actualizar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function getLista(bean As bCliente) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bCliente

sql = "SELECT sruc, srazsocial, sdireccion, nestado , sestado FROM proc_cliente_lista("
sql = sql + " cast('" + CStr(bean.sRuc) + "' as character(11)), "
sql = sql + "cast('" + bean.sRazonSocial + "' as character varying))"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bCliente
    If Not IsNull(rst.Fields("sruc")) Then record.sRuc = rst.Fields("sruc").value
    If Not IsNull(rst.Fields("srazsocial")) Then record.sRazonSocial = rst.Fields("srazsocial").value
    If Not IsNull(rst.Fields("sdireccion")) Then record.sDireccion = rst.Fields("sdireccion").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    
    rst.MoveNext
    list.Add record
Wend
Set getLista = list

hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function
